import argparse
import os
import pandas as pd
from model.powerModel.BatteryParser import BatteryParser
from model.powerModel.Pixel import Pixel
from model.windowLengthModel.WindowLengthParser import WindowLengthParser

def parse_args():
    # 解析输入参数
    parser = argparse.ArgumentParser(
        description='Tools for analyse battery consume',
    )
    parser.add_argument('--mode', default="Power",choices=["CONFUSION_MATIX","Power","Window"])
    parser.add_argument('--path', default="batteryStats/Pixel/Expriment/replay/v0.1")
    parser.add_argument('--brand', default="pixel")
    parser.add_argument('--metrics', default="rtc_alarm")
    parser.add_argument('--version', default=14)
    parser.add_argument('--out_path', default="result/output.csv")
    args = parser.parse_args()
    return args

if __name__ == '__main__':
    # policy = "findBug"
    args = parse_args()
    mode = args.mode
    data_path = args.path
    version = args.version


    if mode == "CONFUSION_MATIX":
        battery_parser = BatteryParser(args.out_path)
        all_attri_num = pd.DataFrame()
        for file_name in os.listdir(data_path):
            print(file_name + ": ")
            battery = Pixel(os.path.join(data_path, file_name))
            battery.print_hardware()
            print("\n")
            element = battery_parser.get_hardware_element(battery)
            all_attri_num = pd.concat([all_attri_num, element], axis=0, ignore_index=True)
        battery_parser.analyse_corr(all_attri_num)
    elif mode == "Power":
        battery_parser = BatteryParser(args.out_path, args.path)
        battery_parser.start_process(version)
        battery_parser.to_csv()
        battery_parser.plot_stategy_pic()
        battery_parser.print_stats("rtc_alarm")
        battery_parser.print_stats("drain")
        battery_parser.plot_time_drain()
    elif mode == "Window":
        wParse = WindowLengthParser(data_path)
        wParse.parse()
        print("yes")
        wParse.plot()
